package SquareFighters;

import SquareFighters.Attack.*;
import java.awt.*;

/**
 *
 * @author Someperson1
 */
public final class Actor {

    private int maxskills[] = new int[3];
    private int skills[] = new int[3];
    public boolean usem, uses, useh;
    int frame;
    Rectangle bounds;
    Magic magic;
    Sword sword;

    public Actor(Field field) {
        bounds = new Rectangle(field.pos[0] - 10, field.pos[1] - 10, 20, 20);
        modMaxHealth(10);
        modMaxMagic(10);
        modMaxStr(10);
        modHealth(10);
        modStr(10);
        modMagic(10);
    }

    public void draw(Graphics g, int width, int posx, int posy, int dir) {
        if (useh) {
            if (frame % 4 == 0 || frame % 4 == 1) {
                g.setColor(Color.RED);
            } else {
                g.setColor(Color.WHITE);
            }
            frame++;
            if (frame >= 20) {
                frame = 0;
                useh = false;
            }
        } else {
            g.setColor(Color.white);
        }
        bounds.setLocation(posx - 10, posy - 10);
        g.fillRect(posx - 10, posy - 10, 20, 20);
        g.setColor(Color.red);
        g.drawRect(width - getMaxHealth() / 2, 2, getMaxHealth() + 1, 11);
        g.setColor(new Color(150, 0, 0));
        g.fillRect(width - getMaxHealth() / 2 + 1, 3, getHealth(), 10);
        g.setColor(Color.blue);
        g.drawRect(2, 2, getMaxMagic() + 1, 11);
        g.setColor(new Color(0, 0, 150));
        g.fillRect(3, 3, getMagic(), 10);
        g.setColor(Color.green);
        g.drawRect(width * 2 - 104, 2, getMaxStr() + 1, 11);
        g.setColor(new Color(0, 150, 0));
        g.fillRect(width * 2 - 103, 3, getStr(), 10);
        if (usem) {
            if (magic == null) {
                magic = new Magic(posx, posy, dir, this);
            }
            magic.draw(g);
            if (magic.frame >= 20) {
                usem = false;
                magic = null;
            }
        }
        if (uses) {
            if (sword == null) {
                sword = new Sword(posx, posy, dir);
            }
            sword.draw(g);
            if (sword.frame >= 5) {
                uses = false;
                sword = null;
            }
        }
    }

    public int getMaxHealth() {
        return maxskills[0];
    }

    public int getHealth() {
        return skills[0];
    }

    public int getMaxMagic() {
        return maxskills[1];
    }

    public int getMagic() {
        return skills[1];
    }

    public int getMaxStr() {
        return maxskills[2];
    }

    public int getStr() {
        return skills[2];
    }

    public void modMaxHealth(int x) {
        maxskills[0] += x;
        if (getMaxHealth() >= 100) {
            maxskills[0] = 100;
        }
        if (getMaxHealth() < 10) {
            maxskills[0] = 10;
        }
        modHealth(100);
    }

    public void modHealth(int x) {
        skills[0] += x;
        if (getHealth() >= getMaxHealth()) {
            skills[0] = getMaxHealth();
        }
        if (getHealth() < 0) {
            skills[0] = 0;
        }
        if (x < 0) {
            useh = true;
        }
    }

    public void modMaxMagic(int x) {
        maxskills[1] += x;
        if (getMaxMagic() >= 100) {
            maxskills[1] = 100;
        }
        if (getMaxMagic() < 10) {
            maxskills[1] = 10;
        }
        modMagic(100);
    }

    public void modMagic(int x) {
        skills[1] += x;
        if (getMagic() >= getMaxMagic()) {
            skills[1] = getMaxMagic();
        }
        if (getMagic() < 0) {
            skills[1] = 0;
        }
    }

    public void modMaxStr(int x) {
        maxskills[2] += x;
        if (getMaxStr() >= 100) {
            maxskills[2] = 100;
        }
        if (getMaxStr() < 10) {
            maxskills[2] = 10;
        }
        modStr(100);
    }

    public void modStr(int x) {
        skills[2] += x;
        if (getStr() >= getMaxStr()) {
            skills[2] = getMaxStr();
        }
        if (getStr() < 0) {
            skills[2] = 0;
        }
    }
}
